import 'dart:io';

import 'package:business_user/api/user_client.dart';
import 'package:flutter/cupertino.dart';
import 'package:lib_core/lib_core.dart';
import 'package:lib_core/widget/loading.dart';

class TestLoginLogic extends GetxController {
  /*final _authImpl = AuthService.to;
  final _userClient = UserClient();

  // 同意协议
  final isAgreed = false.obs;
  final account = ''.obs..firstRebuild = false;
  final password = ''.obs..firstRebuild = false;
  final verifyCode = ''.obs..firstRebuild = false;

  @override
  void onInit() {
    super.onInit();
    // account.value = _authImpl.lastAccount ?? '';
    account.value = 'ZD2862206001';
    password.value = 'ZD@202206';
  }

  void login(Future<LoginModel?> Function() login, Function(LoginModel) onSuccess) async {
    Loading.show();
    final loginModel = await login.call().tryAwaitCommon((e) => e.showError);
    Loading.dismiss();
    if (loginModel != null) {
      _authImpl.saveUser(loginModel);
      onSuccess.call(loginModel);
    }
  }

  void loginByPwd(Function(LoginModel) onSuccess) {
    login(() async {
      final params = {
        'appVersion': '3.0.31',
        'appType': Platform.isAndroid ? 'Android' : 'IOS',
        'userId': account.value,
        'userPass': EncryptUtils.encrypt(password.value),
        'privacyAgreementVersion': VersionCst.privacyPolicyVersion,
        'userAgreementVersion': VersionCst.serviceAgreementVersion,
      };
      final rsp = await _userClient.loginPwd(params);
      return rsp;
    }, onSuccess);
  }

  void loginByVerifyCode(Function(LoginModel) onSuccess, int code) {
    login(() async {
      final params = {
        'userId': account.value,
        'mobileCode': code,
        'privacyAgreementVersion': VersionCst.privacyPolicyVersion,
        'userAgreementVersion': VersionCst.serviceAgreementVersion,
      };
      final rsp = await _userClient.loginPwd(params);
      return rsp;
    }, onSuccess);
  }*/
}
